package edu.towson.cosc.cosc455.astewart.compiler;
import java.io.*;
/**
 * Converts the lolcode tags to html tags and writes them to an output file
 * @author AndrewStewart
 *
 */
public class MySemanticAnalyzer {
	public void writeOutput(){
	Writer writer = null;
	String tag;
	
	
	/**
	 * Creates an html file and adds the html tags after they have been converted
	 */
	try {
	    writer = new BufferedWriter(new FileWriter(MyCompiler.htmlFile));
	    	for (int i=0; i<MyCompiler.parseTree.size();i++){
	    	tag= MyCompiler.parseTree.get(i);
	    	if (tag.equalsIgnoreCase("#KTHXBYE"))
	    		writer.write("</html>");
	    	else if (tag.equalsIgnoreCase("#HAI"))
	    		writer.write("<html>");
	    	else if (tag.equalsIgnoreCase("#TLDR"))
	    		writer.write("-->");
	    	else if (tag.equalsIgnoreCase("#OBTW"))
	    		writer.write("<!--");
	    	else if (tag.equalsIgnoreCase("#MAEK HEAD"))
	    		writer.write("<head>");	 
	    	else if (tag.equalsIgnoreCase("#OIC HEAD"))
	    		writer.write("</head>");
	    	else if (tag.equalsIgnoreCase("#GIMMEH TITLE"))
	    		writer.write("<title>");
	    	else if (tag.equalsIgnoreCase("#MKAY TITLE"))
	    		writer.write("</title>");
	    	else if (tag.equalsIgnoreCase("#MAEK PARAGRAF"))
	    		writer.write("<p>");
	    	else if (tag.equalsIgnoreCase("#OIC PARAGRAPH"))
	    		writer.write("</p>");
	    	else if (tag.equalsIgnoreCase("#GIMMEH BOLD"))
	    		writer.write("<b>");
	    	else if (tag.equalsIgnoreCase("#MKAY BOLD"))
	    		writer.write("</b>");
	    	else if (tag.equalsIgnoreCase("#GIMMEH ITALICS"))
	    		writer.write("<i>");
	    	else if (tag.equalsIgnoreCase("#MKAY ITALICS"))
	    		writer.write("</i>");
	    	else if (tag.equalsIgnoreCase("#MAEK LIST"))
	    		writer.write("<ul>");
	    	else if (tag.equalsIgnoreCase("#OIC LIST"))
	    		writer.write("</ul>");
	    	else if (tag.equalsIgnoreCase("#GIMMEH ITEM"))
	    		writer.write("<li>");
	    	else if (tag.equalsIgnoreCase("#MKAY ITEM"))
	    		writer.write("</li>");
	    	else if (tag.equalsIgnoreCase("#GIMMEH NEWLINE"))
	    		writer.write("<br>");
	    	else if (tag.equalsIgnoreCase("#GIMMEH SOUNDZ"))
	    		writer.write("<audio controls>\n <source src= \" ");
	    	else if (tag.equalsIgnoreCase("#MKAY AUDIO"))
	    		writer.write("\"> \n </audio>");
	    	else if (tag.equalsIgnoreCase("#GIMMEH VIDZ"))
	    		writer.write("<iframe src=\"");
	    	else if (tag.equalsIgnoreCase("#MKAY VIDEO"))
	    		writer.write("\"/>");
	    	else if (!tag.startsWith("#"))
	    		writer.write(tag);
	    	}
	    		
	   // }
	} catch (IOException e) {
	    e.printStackTrace();
	} finally {
	    if (writer != null) try { writer.close(); } catch (IOException ignore) {}
	}
	}
}